//
//  LayoutSubivewOfUIViewViewController.m
//  CoreAnimation
//
//  Created by 张国文 on 16/10/9.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "LayoutSubivewOfUIViewViewController.h"
#import "CusomAutoLayoutView.h"

@interface LayoutSubivewOfUIViewViewController ()

@property (nonatomic, strong) CusomAutoLayoutView *customView;
@property (nonatomic, assign) UIDeviceOrientation currentOriention; // 当前设备方向

@end

@implementation LayoutSubivewOfUIViewViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    // 设备方向通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
    
    self.customView = [[CusomAutoLayoutView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    self.customView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_customView];
}

- (void)orientationChange:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    switch (orientation) {
        case UIDeviceOrientationPortrait:
        {
            NSLog(@"设备正面");
            self.currentOriention = UIDeviceOrientationPortrait;
            [self.customView setNeedsLayout];
            
            break;
        }
        case UIDeviceOrientationLandscapeLeft:
        {
            NSLog(@"设备左面");
            self.currentOriention = UIDeviceOrientationLandscapeLeft;
            [self.customView setNeedsLayout];
            break;
        }
        case UIDeviceOrientationLandscapeRight:
        {
            NSLog(@"设备右边");
            self.currentOriention = UIDeviceOrientationLandscapeRight;
            [self.customView setNeedsLayout];
            break;
        }
        case UIDeviceOrientationPortraitUpsideDown:
        {
            NSLog(@"设备向下");
            self.currentOriention = UIDeviceOrientationPortraitUpsideDown;
            [self.customView setNeedsLayout];
            break;
        }
        default:
            break;
    }
}



@end
